import request from '@/utils/request'
import BaseUrl from './BaseUrl'
// import { uuid } from '../utils/uuid'
const systemPath = BaseUrl.getDefaultBaseUrl()
const modulePath = systemPath + '/api-uaa/oauth'
const modulePath1 = systemPath + '/api-user'
// const modulePath = systemPath + '/auth'
import qs from 'qs'

const code_path = systemPath + '/api-uaa/validata'
export function loginByUsername(userinfo) {
  // const data = {
  //   username: userinfo.username,
  //   password: userinfo.password
  // }
  console.log(userinfo)
  const auth = 'webApp:webApp'
  return request({
    url: modulePath + '/token',
    // url: modulePath + '/login',
    method: 'post',
    data: qs.stringify(userinfo),
    // data,
    headers: { 'Authorization': 'Basic ' + btoa(auth), 'Content-Type': 'application/x-www-form-urlencoded' }
  })
}

export function logout() {
  return request({
    // url: modulePath + '/logout',
    url: modulePath + '/remove/token',
    method: 'get'
  })
}

export function getUserInfo(token) {
  return request({
    // url: modulePath + '/info',
    url: modulePath1 + '/users/current',
    method: 'get',
    params: { token }
  })
}
export function getcode(id) {
  return request({
    url: code_path + '/code/' + id,
    method: 'get'
  })
}

